package com.baibei.module;

import android.content.pm.PackageManager;

import com.baibei.ebec.sdk.ApiConstant;
import com.baibei.ebec.sdk.BuildConfig;
import com.baibei.ebec.sdk.TokenInfo;
import com.baibei.model.InoutFundParam;
import com.baibei.sdk.SdkConfig;
import com.blankj.utilcode.utils.Utils;
import com.rae.swift.RaeSharedPreferences;
import com.rae.swift.session.SessionManager;

/**
 * 出入金提供者
 * Created by shenminjie on 2017/11/3.
 * mail:shenminjie@100bei.com
 */

public class InoutFundParamProvider {

    /**
     * 获取数据出入金
     * 封装好的入参
     */
    public static InoutFundParam get() {
        return get(null);
    }

    public static InoutFundParam get(String url) {
        InoutFundParam param = new InoutFundParam();
        TokenInfo tokenInfo = SessionManager.getDefault().getUserToken();
        param.setExchange(BuildConfig.EXCHANGE);
        param.setUrl(url);
        param.setMemberChannel(ApiConstant.MEMBER_CHANNEL);
        SdkConfig config = new RaeSharedPreferences(Utils.getContext()).create(SdkConfig.class);
        if (tokenInfo != null && config != null) {
            param.setAccessToken(tokenInfo.getAccessToken());
            param.setRefreshToken(tokenInfo.getRefreshToken());
            param.setAppKey(BuildConfig.APPKEY);
            param.setAppSecret(BuildConfig.APPSECRETE);
            param.setDeviceId(config.getDeviceId());
        }
        try {
            param.setVersion(Utils.getContext().getPackageManager().getPackageInfo(Utils.getContext().getPackageName(), PackageManager.GET_META_DATA).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return param;
    }

}
